import type { AssessmentPrice } from '@/services/price-sheet/getBwPriceAskWords'
import { ComboPriceTimer, DataIndex } from '@/core/enums/name'
import { PlatformEnum, PricePlatform } from '@/core/enums/platform'
import { onLinePeriodMap } from '@/core/mapper/priceSheet'

const fromKey = (days: AssessmentPrice['days']) => {
  const daysMap = {
    365: 0,
    180: 1,
    90: 2,
    30: 3,
    730: 4
  }

  return daysMap[days]
}

function fromClientType(clientType: AssessmentPrice['clientType']): PricePlatform {
  const typeMap = {
    [PlatformEnum.Platform]: PricePlatform.Platform,
    [PlatformEnum.PC]: PricePlatform.PC,
    [PlatformEnum.MOBILE]: PricePlatform.Mobile
  }

  return typeMap[clientType]
}

export const priseTableReduce = (data: AssessmentPrice[], table: typeof priceTable) => {
  return data.reduce((p, n) => {
    const x = fromKey(n.days)
    const y = `${fromClientType(n.clientType)}${n.onlinePeriodDays}x${n.onlinePeriodHours}` as DataIndex

    Object.assign(p[x][y], n)

    return p
  }, table)
}

export const priceTable = [
  {
    timer: {
      value: ComboPriceTimer.YEAR,
      shop: true
    },
    [DataIndex.Platform7x24]: {
      assessmentPrice: 0,
      clientType: PlatformEnum.Platform,
      days: 365,
      rowIndex: 0,
      onlinePeriodDays: 7,
      onlinePeriodHours: 24,
      priceTypeId: 3,
      quote: `7天*24小时(元)`,
      timer: ComboPriceTimer.YEAR,
      dataIndex: DataIndex.Platform7x24,
      columnName: fromClientType(PlatformEnum.Platform),
      onLinePeriod: onLinePeriodMap[DataIndex.Platform7x24]
    },
    [DataIndex.Platform5x8]: {
      assessmentPrice: 0,
      clientType: PlatformEnum.Platform,
      days: 365,
      rowIndex: 0,
      onlinePeriodDays: 5,
      onlinePeriodHours: 8,
      priceTypeId: 6,
      quote: `5天*8小时(元)`,
      timer: ComboPriceTimer.YEAR,
      dataIndex: DataIndex.Platform5x8,
      columnName: fromClientType(PlatformEnum.Platform),
      onLinePeriod: onLinePeriodMap[DataIndex.Platform5x8]
    },
    [DataIndex.Mobile7x24]: {
      assessmentPrice: 0,
      clientType: PlatformEnum.MOBILE,
      days: 365,
      rowIndex: 0,
      onlinePeriodDays: 7,
      onlinePeriodHours: 24,
      priceTypeId: 2,
      quote: `7天*24小时(元)`,
      timer: ComboPriceTimer.YEAR,
      dataIndex: DataIndex.Mobile7x24,
      columnName: fromClientType(PlatformEnum.MOBILE),
      onLinePeriod: onLinePeriodMap[DataIndex.Mobile7x24]
    },
    [DataIndex.Mobile5x8]: {
      assessmentPrice: 0,
      clientType: PlatformEnum.MOBILE,
      days: 365,
      rowIndex: 0,
      onlinePeriodDays: 5,
      onlinePeriodHours: 8,
      priceTypeId: 5,
      quote: `5天*8小时(元)`,
      timer: ComboPriceTimer.YEAR,
      dataIndex: DataIndex.Mobile5x8,
      columnName: fromClientType(PlatformEnum.MOBILE),
      onLinePeriod: onLinePeriodMap[DataIndex.Mobile5x8]
    },
    [DataIndex.Pc7x24]: {
      assessmentPrice: 0,
      clientType: PlatformEnum.PC,
      days: 365,
      rowIndex: 0,
      onlinePeriodDays: 7,
      onlinePeriodHours: 24,
      priceTypeId: 1,
      quote: `7天*24小时(元)`,
      timer: ComboPriceTimer.YEAR,
      dataIndex: DataIndex.Pc7x24,
      columnName: fromClientType(PlatformEnum.PC),
      onLinePeriod: onLinePeriodMap[DataIndex.Pc7x24]
    },
    [DataIndex.Pc5x8]: {
      assessmentPrice: 0,
      clientType: PlatformEnum.PC,
      days: 365,
      rowIndex: 0,
      onlinePeriodDays: 5,
      onlinePeriodHours: 8,
      priceTypeId: 4,
      quote: `5天*8小时(元)`,
      timer: ComboPriceTimer.YEAR,
      dataIndex: DataIndex.Pc5x8,
      columnName: fromClientType(PlatformEnum.PC),
      onLinePeriod: onLinePeriodMap[DataIndex.Pc5x8]
    }
  },
  {
    timer: {
      value: ComboPriceTimer.HALF_YEAR,
      shop: true
    },
    [DataIndex.Platform7x24]: {
      assessmentPrice: 0,
      clientType: PlatformEnum.Platform,
      days: 180,
      rowIndex: 1,
      onlinePeriodDays: 7,
      onlinePeriodHours: 24,
      priceTypeId: 9,
      quote: `7天*24小时(元)`,
      timer: ComboPriceTimer.HALF_YEAR,
      dataIndex: DataIndex.Platform7x24,
      columnName: fromClientType(PlatformEnum.Platform),
      onLinePeriod: onLinePeriodMap[DataIndex.Platform7x24]
    },
    [DataIndex.Platform5x8]: {
      assessmentPrice: 0,
      clientType: PlatformEnum.Platform,
      days: 180,
      rowIndex: 1,
      onlinePeriodDays: 5,
      onlinePeriodHours: 8,
      priceTypeId: 12,
      quote: `5天*8小时(元)`,
      timer: ComboPriceTimer.HALF_YEAR,
      dataIndex: DataIndex.Platform5x8,
      columnName: fromClientType(PlatformEnum.Platform),
      onLinePeriod: onLinePeriodMap[DataIndex.Platform5x8]
    },
    [DataIndex.Mobile7x24]: {
      assessmentPrice: 0,
      clientType: PlatformEnum.MOBILE,
      days: 180,
      rowIndex: 1,
      onlinePeriodDays: 7,
      onlinePeriodHours: 24,
      priceTypeId: 8,
      quote: `7天*24小时(元)`,
      timer: ComboPriceTimer.HALF_YEAR,
      dataIndex: DataIndex.Mobile7x24,
      columnName: fromClientType(PlatformEnum.MOBILE),
      onLinePeriod: onLinePeriodMap[DataIndex.Mobile7x24]
    },
    [DataIndex.Mobile5x8]: {
      assessmentPrice: 0,
      clientType: PlatformEnum.MOBILE,
      days: 180,
      rowIndex: 1,
      onlinePeriodDays: 5,
      onlinePeriodHours: 8,
      priceTypeId: 11,
      quote: `5天*8小时(元)`,
      timer: ComboPriceTimer.HALF_YEAR,
      dataIndex: DataIndex.Mobile5x8,
      columnName: fromClientType(PlatformEnum.MOBILE),
      onLinePeriod: onLinePeriodMap[DataIndex.Mobile5x8]
    },
    [DataIndex.Pc7x24]: {
      assessmentPrice: 0,
      clientType: PlatformEnum.PC,
      days: 180,
      rowIndex: 1,
      onlinePeriodDays: 7,
      onlinePeriodHours: 24,
      priceTypeId: 7,
      quote: `7天*24小时(元)`,
      timer: ComboPriceTimer.HALF_YEAR,
      dataIndex: DataIndex.Pc7x24,
      columnName: fromClientType(PlatformEnum.PC),
      onLinePeriod: onLinePeriodMap[DataIndex.Pc7x24]
    },
    [DataIndex.Pc5x8]: {
      assessmentPrice: 0,
      clientType: PlatformEnum.PC,
      days: 180,
      rowIndex: 1,
      onlinePeriodDays: 5,
      onlinePeriodHours: 8,
      priceTypeId: 10,
      quote: `5天*8小时(元)`,
      timer: ComboPriceTimer.HALF_YEAR,
      dataIndex: DataIndex.Pc5x8,
      columnName: fromClientType(PlatformEnum.PC),
      onLinePeriod: onLinePeriodMap[DataIndex.Pc5x8]
    }
  },
  {
    timer: {
      value: ComboPriceTimer.QUARTET,
      shop: true
    },
    [DataIndex.Platform7x24]: {
      assessmentPrice: 0,
      clientType: PlatformEnum.Platform,
      days: 90,
      rowIndex: 2,
      onlinePeriodDays: 7,
      onlinePeriodHours: 24,
      priceTypeId: 15,
      quote: `7天*24小时(元)`,
      timer: ComboPriceTimer.QUARTET,
      dataIndex: DataIndex.Platform7x24,
      columnName: fromClientType(PlatformEnum.Platform),
      onLinePeriod: onLinePeriodMap[DataIndex.Platform7x24]
    },
    [DataIndex.Platform5x8]: {
      assessmentPrice: 0,
      clientType: PlatformEnum.Platform,
      days: 90,
      rowIndex: 2,
      onlinePeriodDays: 5,
      onlinePeriodHours: 8,
      priceTypeId: 18,
      quote: `5天*8小时(元)`,
      timer: ComboPriceTimer.QUARTET,
      dataIndex: DataIndex.Platform5x8,
      columnName: fromClientType(PlatformEnum.Platform),
      onLinePeriod: onLinePeriodMap[DataIndex.Platform5x8]
    },
    [DataIndex.Mobile7x24]: {
      assessmentPrice: 0,
      clientType: PlatformEnum.MOBILE,
      days: 90,
      rowIndex: 2,
      onlinePeriodDays: 7,
      onlinePeriodHours: 24,
      priceTypeId: 14,
      quote: `7天*24小时(元)`,
      timer: ComboPriceTimer.QUARTET,
      dataIndex: DataIndex.Mobile7x24,
      columnName: fromClientType(PlatformEnum.MOBILE),
      onLinePeriod: onLinePeriodMap[DataIndex.Mobile7x24]
    },
    [DataIndex.Mobile5x8]: {
      assessmentPrice: 0,
      clientType: PlatformEnum.MOBILE,
      days: 90,
      rowIndex: 2,
      onlinePeriodDays: 5,
      onlinePeriodHours: 8,
      priceTypeId: 17,
      quote: `5天*8小时(元)`,
      timer: ComboPriceTimer.QUARTET,
      dataIndex: DataIndex.Mobile5x8,
      columnName: fromClientType(PlatformEnum.MOBILE),
      onLinePeriod: onLinePeriodMap[DataIndex.Mobile5x8]
    },
    [DataIndex.Pc7x24]: {
      assessmentPrice: 0,
      clientType: PlatformEnum.PC,
      days: 90,
      rowIndex: 2,
      onlinePeriodDays: 7,
      onlinePeriodHours: 24,
      priceTypeId: 13,
      quote: `7天*24小时(元)`,
      timer: ComboPriceTimer.QUARTET,
      dataIndex: DataIndex.Pc7x24,
      columnName: fromClientType(PlatformEnum.PC),
      onLinePeriod: onLinePeriodMap[DataIndex.Pc7x24]
    },
    [DataIndex.Pc5x8]: {
      assessmentPrice: 0,
      clientType: PlatformEnum.PC,
      days: 90,
      rowIndex: 2,
      onlinePeriodDays: 5,
      onlinePeriodHours: 8,
      priceTypeId: 16,
      quote: `5天*8小时(元)`,
      timer: ComboPriceTimer.QUARTET,
      dataIndex: DataIndex.Pc5x8,
      columnName: fromClientType(PlatformEnum.PC),
      onLinePeriod: onLinePeriodMap[DataIndex.Pc5x8]
    }
  },
  {
    timer: {
      value: ComboPriceTimer.MONTH,
      shop: false
    },
    [DataIndex.Platform7x24]: {
      assessmentPrice: 0,
      clientType: PlatformEnum.Platform,
      days: 30,
      rowIndex: 3,
      onlinePeriodDays: 7,
      onlinePeriodHours: 24,
      priceTypeId: 21,
      quote: `7天*24小时(元)`,
      timer: ComboPriceTimer.MONTH,
      dataIndex: DataIndex.Platform7x24,
      columnName: fromClientType(PlatformEnum.Platform),
      onLinePeriod: onLinePeriodMap[DataIndex.Platform7x24]
    },
    [DataIndex.Platform5x8]: {
      assessmentPrice: 0,
      clientType: PlatformEnum.Platform,
      days: 30,
      rowIndex: 3,
      onlinePeriodDays: 5,
      onlinePeriodHours: 8,
      priceTypeId: 24,
      quote: `5天*8小时(元)`,
      timer: ComboPriceTimer.MONTH,
      dataIndex: DataIndex.Platform5x8,
      columnName: fromClientType(PlatformEnum.Platform),
      onLinePeriod: onLinePeriodMap[DataIndex.Platform5x8]
    },
    [DataIndex.Mobile7x24]: {
      assessmentPrice: 0,
      clientType: PlatformEnum.MOBILE,
      days: 30,
      rowIndex: 3,
      onlinePeriodDays: 7,
      onlinePeriodHours: 24,
      priceTypeId: 20,
      quote: `7天*24小时(元)`,
      timer: ComboPriceTimer.MONTH,
      dataIndex: DataIndex.Mobile7x24,
      columnName: fromClientType(PlatformEnum.MOBILE),
      onLinePeriod: onLinePeriodMap[DataIndex.Mobile7x24]
    },
    [DataIndex.Mobile5x8]: {
      assessmentPrice: 0,
      clientType: PlatformEnum.MOBILE,
      days: 30,
      rowIndex: 3,
      onlinePeriodDays: 5,
      onlinePeriodHours: 8,
      priceTypeId: 23,
      quote: `5天*8小时(元)`,
      timer: ComboPriceTimer.MONTH,
      dataIndex: DataIndex.Mobile5x8,
      columnName: fromClientType(PlatformEnum.MOBILE),
      onLinePeriod: onLinePeriodMap[DataIndex.Mobile5x8]
    },
    [DataIndex.Pc7x24]: {
      assessmentPrice: 0,
      clientType: PlatformEnum.PC,
      days: 30,
      rowIndex: 3,
      onlinePeriodDays: 7,
      onlinePeriodHours: 24,
      priceTypeId: 19,
      quote: `7天*24小时(元)`,
      timer: ComboPriceTimer.MONTH,
      dataIndex: DataIndex.Pc7x24,
      columnName: fromClientType(PlatformEnum.PC),
      onLinePeriod: onLinePeriodMap[DataIndex.Pc7x24]
    },
    [DataIndex.Pc5x8]: {
      assessmentPrice: 0,
      clientType: PlatformEnum.PC,
      days: 30,
      rowIndex: 3,
      onlinePeriodDays: 5,
      onlinePeriodHours: 8,
      priceTypeId: 22,
      quote: `5天*8小时(元)`,
      timer: ComboPriceTimer.MONTH,
      dataIndex: DataIndex.Pc5x8,
      columnName: fromClientType(PlatformEnum.PC),
      onLinePeriod: onLinePeriodMap[DataIndex.Pc5x8]
    }
  },
  {
    timer: {
      value: ComboPriceTimer.TwoYEAR,
      shop: true
    },
    [DataIndex.Platform7x24]: {
      assessmentPrice: 0,
      clientType: PlatformEnum.Platform,
      days: 730,
      rowIndex: 4,
      onlinePeriodDays: 7,
      onlinePeriodHours: 24,
      priceTypeId: 27,
      quote: `7天*24小时(元)`,
      timer: ComboPriceTimer.TwoYEAR,
      dataIndex: DataIndex.Platform7x24,
      columnName: fromClientType(PlatformEnum.Platform),
      onLinePeriod: onLinePeriodMap[DataIndex.Platform7x24]
    },
    [DataIndex.Platform5x8]: {
      assessmentPrice: 0,
      clientType: PlatformEnum.Platform,
      days: 730,
      rowIndex: 4,
      onlinePeriodDays: 5,
      onlinePeriodHours: 8,
      priceTypeId: 30,
      quote: `5天*8小时(元)`,
      timer: ComboPriceTimer.TwoYEAR,
      dataIndex: DataIndex.Platform5x8,
      columnName: fromClientType(PlatformEnum.Platform),
      onLinePeriod: onLinePeriodMap[DataIndex.Platform5x8]
    },
    [DataIndex.Mobile7x24]: {
      assessmentPrice: 0,
      clientType: PlatformEnum.MOBILE,
      days: 730,
      rowIndex: 4,
      onlinePeriodDays: 7,
      onlinePeriodHours: 24,
      priceTypeId: 26,
      quote: `7天*24小时(元)`,
      timer: ComboPriceTimer.TwoYEAR,
      dataIndex: DataIndex.Mobile7x24,
      columnName: fromClientType(PlatformEnum.MOBILE),
      onLinePeriod: onLinePeriodMap[DataIndex.Mobile7x24]
    },
    [DataIndex.Mobile5x8]: {
      assessmentPrice: 0,
      clientType: PlatformEnum.MOBILE,
      days: 730,
      rowIndex: 4,
      onlinePeriodDays: 5,
      onlinePeriodHours: 8,
      priceTypeId: 29,
      quote: `5天*8小时(元)`,
      timer: ComboPriceTimer.TwoYEAR,
      dataIndex: DataIndex.Mobile5x8,
      columnName: fromClientType(PlatformEnum.MOBILE),
      onLinePeriod: onLinePeriodMap[DataIndex.Mobile5x8]
    },
    [DataIndex.Pc7x24]: {
      assessmentPrice: 0,
      clientType: PlatformEnum.PC,
      days: 730,
      rowIndex: 4,
      onlinePeriodDays: 7,
      onlinePeriodHours: 24,
      priceTypeId: 25,
      quote: `7天*24小时(元)`,
      timer: ComboPriceTimer.TwoYEAR,
      dataIndex: DataIndex.Pc7x24,
      columnName: fromClientType(PlatformEnum.PC),
      onLinePeriod: onLinePeriodMap[DataIndex.Pc7x24]
    },
    [DataIndex.Pc5x8]: {
      assessmentPrice: 0,
      clientType: PlatformEnum.PC,
      days: 730,
      rowIndex: 4,
      onlinePeriodDays: 5,
      onlinePeriodHours: 8,
      priceTypeId: 28,
      quote: `5天*8小时(元)`,
      timer: ComboPriceTimer.TwoYEAR,
      dataIndex: DataIndex.Pc5x8,
      columnName: fromClientType(PlatformEnum.PC),
      onLinePeriod: onLinePeriodMap[DataIndex.Pc5x8]
    }
  }
]
